﻿using System;
using Peter.Common;
using Peter.Common.MainMenu;
using Peter.Data;

namespace Peter.Logic
{
   /// <summary>
   /// Represents a web view model.
   /// </summary>
   public sealed class ModelWeb : PeterDocument
   {
      private Uri m_Url;

      /// <summary>
      /// Initializes a new web view model.
      /// </summary>
      public ModelWeb ()
      {
         this.Title = "Web Browser";
         this.Icon = MainMenuIcon.Domain;
         this.ContentId = Guids.WEB_BROWSER;
      }

      /// <summary>
      /// Gets or Sets the url.
      /// </summary>
      public Uri Url
      {
         get { return this.m_Url; }
         set
         {
            this.m_Url = value;
            if (this.m_Url == null)
               this.ContentId = Guids.WEB_BROWSER;
            else if (!this.m_Url.IsAbsoluteUri)
               this.ContentId = Guids.WEB_BROWSER + "|" + this.m_Url.OriginalString;
            else
               this.ContentId = Guids.WEB_BROWSER + "|" + this.m_Url.AbsoluteUri;
         }
      }

      /// <summary>
      /// Creates a new web view.
      /// </summary>
      /// <param name="targetUrl">The target url to navigate to.</param>
      public void NewWebView (Uri targetUrl)
      {
         this.Peter.AddDocument(new ModelWeb { Url = targetUrl});
      }
   }
}
